package com.yint.tree;

/**
 * 反相器
 * <p>
 * Created by 殷田 on 2018/5/4.
 */
public class Inverter extends Decorator {

    public Inverter() {

    }

    public Inverter(Leaf sub) {
        setSub(sub);
    }

    @Override
    protected synchronized STATUS onTick(Tree tree) {
        if (!getSub().entry(tree)) {
            getSub().leave(tree);
            return STATUS.FAILED;
        }
        STATUS state = getSub().tick(tree);
        if (state == STATUS.SUCCEED) {
            return STATUS.FAILED;
        }
        if (state == STATUS.FAILED) {
            return STATUS.SUCCEED;
        }
        return state;
    }
}
